#pragma once
#include <iostream>
#include <string>
#include <memory>
#include <functional>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "log.hpp"
#include "unistd.h"
#include "fcntl.h"

using namespace MyLog;
class Nocopy
{
public:
    Nocopy(){}
    ~Nocopy(){}
    Nocopy(const Nocopy&) = delete;
    Nocopy operator=(const Nocopy&) = delete;
};

enum ExitCode
{
    OK = 0,
    USAGE_ERR,
    SOCKET_ERR,
    BIND_ERR,
    LISTEN_ERR,
    CONNECT_ERR,
    FORK_ERR,
    POPEN_ERR,
    CREATE_EPOLL_ERR,
    EPOLL_CTL_ADD_ERR
};

void nonBlock(int fd)
{
    int fl = fcntl(fd, F_GETFL);    
    if(fl < 0) {
        LOG(loglevel::WARINING) << "get fd error";
    }
    fcntl(fd, F_SETFL, fl | O_NONBLOCK);
}

#define CONVERT(addr) ((struct sockaddr*)&addr)